package com.yike.websocket.controller;

import com.yike.websocket.param.MessageReminderParam;
import com.yike.websocket.util.MessageReminderUtil;
import com.yike.websocket.util.WebsocketUtil;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * @author Sakura
 * @date 2024/9/13 13:38
 */
@RestController
@RequestMapping("/msg")
@Log
public class MsgController {

    @Autowired
    private MessageReminderUtil messageReminderUtil;

    @PostMapping("/send")
    public void send(@RequestParam("id") String id, @RequestParam("message") String message) {
        log.info("发送消息给：" + id + "-" + message);
        WebsocketUtil.sendMessage(id, message);
    }

    @PostMapping("/sendAll")
    public void sendAll(@RequestParam("message") String message) {
        log.info("群发消息：" + message);
        WebsocketUtil.sendMessageForAll(message);
    }

    @PostMapping("/sendUserList")
    public void sendAll(@RequestParam("userIds") Set<String> userIds, @RequestParam("message") String message) {
        log.info("发送多人消息：" + userIds.toString() + message);
        WebsocketUtil.sendMessageForAll(message);
    }

    @PostMapping("/sendMessageReminder")
    public void senMessageReminder(@RequestBody MessageReminderParam messageReminderParam) {
        log.info("发送MessageReminder消息：" + messageReminderParam.toString());
        messageReminderUtil.sendMessageReminder(messageReminderParam.getUserId().toString(), messageReminderParam);
    }
}
